package org.gesplan.entity;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author David
 */
@Entity
@Table(name = "material_building")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "MaterialBuilding.findAll", query = "SELECT m FROM MaterialBuilding m"),
    @NamedQuery(name = "MaterialBuilding.findById", query = "SELECT m FROM MaterialBuilding m WHERE m.id = :id"),
    @NamedQuery(name = "MaterialBuilding.findByDateRel", query = "SELECT m FROM MaterialBuilding m WHERE m.dateRel = :dateRel"),
    @NamedQuery(name = "MaterialBuilding.findByPrice", query = "SELECT m FROM MaterialBuilding m WHERE m.price = :price"),
    @NamedQuery(name = "MaterialBuilding.findByAmount", query = "SELECT m FROM MaterialBuilding m WHERE m.amount = :amount"),
    @NamedQuery(name = "MaterialBuilding.findByTotal", query = "SELECT m FROM MaterialBuilding m WHERE m.total = :total"),
})
public class MaterialBuilding implements Serializable {
    
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);    
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @Basic(optional = false)
    @Column(name = "date_rel")
    @Temporal(TemporalType.DATE)
    private Date dateRel;
    @Column(name = "price")
    private Float price;
    @Column(name = "amount")
    private Float amount;
    @Column(name = "total")
    private Float total;
    @Column(name = "comments")
    private String comments;
    @JoinColumn(name = "material_id", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private Material materialId;
    @JoinColumn(name = "building_id", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private Building buildingId;


    public MaterialBuilding() { }


    public MaterialBuilding(Integer id) {
        this.id = id;
    }


    public MaterialBuilding(Integer id, Date dateRel) {
        this.id = id;
        this.dateRel = dateRel;
    }


    public Integer getId() {
        return id;
    }


    public void setId(Integer id) {
        Integer oldId = this.id;
        this.id = id;
        changeSupport.firePropertyChange("id", oldId, id);
    }


    public Date getDateRel() {
        return dateRel;
    }


    public void setDateRel(Date dateRel) {
        Date oldDateRel = this.dateRel;
        this.dateRel = dateRel;
        changeSupport.firePropertyChange("dateRel", oldDateRel, dateRel);        
    }


    public Float getPrice() {
        return price;
    }


    public void setPrice(Float price) {
        Float oldprice = this.price;
        this.price = price;
        changeSupport.firePropertyChange("price", oldprice, price);           
    }


    public Float getAmount() {
        return amount;
    }


    public void setAmount(Float amount) {
        Float oldamount = this.amount;
        this.amount = amount;
        changeSupport.firePropertyChange("amount", oldamount, amount);     
    }


    public Float getTotal() {
        return total;
    }


    public void setTotal(Float total) {
        Float oldtotal = this.total;
        this.total = total;
        changeSupport.firePropertyChange("total", oldtotal, total);  
    }


    public String getComments() {
        return comments;
    }


    public void setComments(String comments) {
        this.comments = comments;
    }


    public Material getMaterialId() {
        return materialId;
    }


    public void setMaterialId(Material materialId) {
        Material oldmaterialId = this.materialId;
        this.materialId = materialId;
        changeSupport.firePropertyChange("materialId", oldmaterialId, materialId);  
    }


    public Building getBuildingId() {
        return buildingId;
    }


    public void setBuildingId(Building buildingId) {
        Building oldbuildingId = this.buildingId;
        this.buildingId = buildingId;
        changeSupport.firePropertyChange("buildingId", oldbuildingId, buildingId);  
    }


    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }


    @Override
    public boolean equals(Object object) {
        if (!(object instanceof MaterialBuilding)) {
            return false;
        }
        MaterialBuilding other = (MaterialBuilding) object;
        return (this.id != null || other.id == null) && (this.id == null || this.id.equals(other.id));
    }


    @Override
    public String toString() {
        return id.toString();
    }
    
    
}